package com.ganzalang.gmall.designpatterns.prototype;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: 不使用原型模式
 * @author: ganzalang
 */
@Slf4j
public class PrototypePatternDemo {

    public static void main(String[] args) throws CloneNotSupportedException {
        Product product = new Product("产品", new Component("组件"));
        Product clone = product.clone();
        log.info("clone: {}", clone);
    }


    @Data
    @AllArgsConstructor
    public static class Component{
        private String name;

        @Override
        protected Component clone() throws CloneNotSupportedException {
            return new Component(this.name);
        }
    }

    @Data
    @AllArgsConstructor
    public static class Product{
        private String name;
        private Component component;

        @Override
        protected Product clone() throws CloneNotSupportedException {
            return new Product(this.name,component.clone());
        }
    }
}
